//package cn.zhc.com.utils;
//
//import android.app.Activity;
//
//import cn.zhc.com.Session;
//import cn.zhc.com.hyphenate.chatuidemo.DemoHelper;
//import cn.zhc.com.hyphenate.chatuidemo.db.DemoDBManager;
//import com.hyphenate.EMCallBack;
//import com.hyphenate.chat.EMClient;
//
///**
// * Created by SpringLoading on 2017/9/3.
// */
//
//public class UtilsHuanXin {
//
////    /**
////     * 注册环信账号
////     *
////     */
////    public static void registerHuanXin(final String userID,final String userName,final Activity mActivity){
////        new Thread(new Runnable() {
////            public void run() {
////                try {
////                    // call method in SDK
////                    EMClient.getInstance().createAccount(userID, userID);
////                    mActivity.runOnUiThread(new Runnable() {
////                        public void run() {
//////                            if (!RegisterUserInfoActivity.this.isFinishing())
//////                                pd.dismiss();
////                            // save current user
////                            DemoHelper.getInstance().setCurrentUserName(userID);
//////                            Toast.makeText(mActivity(), getResources().getString(R.string.Registered_successfully), Toast.LENGTH_SHORT).show();
//////                            finish();
////                            loginHuanXin(userID, userName, mActivity);
////                        }
////                    });
////                } catch (final HyphenateException e) {
////                    mActivity.runOnUiThread(new Runnable() {
////                        public void run() {
//////                            if (!RegisterActivity.this.isFinishing())
//////                                pd.dismiss();
////                            int errorCode=e.getErrorCode();
////                            if(errorCode== EMError.NETWORK_ERROR){
////                                //网络错误
////                                loginHuanXin(userID, userName, mActivity);
////                            }else if(errorCode == EMError.USER_ALREADY_EXIST){
////                                //用户名已存在
////                                loginHuanXin(userID, userName, mActivity);
////                            }else if(errorCode == EMError.USER_AUTHENTICATION_FAILED){
////                                //注册失败，无权限
////                                loginHuanXin(userID, userName, mActivity);
////                            }else if(errorCode == EMError.USER_ILLEGAL_ARGUMENT){
////                                //用户名不合法
////                                loginHuanXin(userID, userName, mActivity);
////                            }else{
////                                //注册失败
////                                loginHuanXin(userID, userName, mActivity);
////                            }
////
////                        }
////                    });
////                }
////            }
////        }).start();
////    }
//
//
//    /**
//     * 登录操作
//     */
//    public static void loginHuanXin(final String userID, final String psw,final Activity mActivity){
//        // After logout，the DemoDB may still be accessed due to async callback, so the DemoDB will be re-opened again.
//        // close it before login to make sure DemoDB not overlap
//        try {
//            DemoDBManager.getInstance().closeDB();
//        }catch (Exception e){
//
//        }
//
//
//        // reset current user name before login
//        DemoHelper.getInstance().setCurrentUserName(userID);
//
//        final long start = System.currentTimeMillis();
//        // call login method
//        EMClient.getInstance().login(userID, psw, new EMCallBack() {
//
//            @Override
//            public void onSuccess() {
//                // ** manually load all local groups and conversation
//                EMClient.getInstance().groupManager().loadAllGroups();
//                EMClient.getInstance().chatManager().loadAllConversations();
//
//                // update current user's display name for APNs
//                boolean updatenick = EMClient.getInstance().pushManager().updatePushNickname(
//                        Session.getUserBean().getUname());
//
////                Logger.e("zhc", "update current user nick = " + updatenick);
////                Logger.e("zhc", "login success");
//
//                // get user's info (this should be get from DemoApplication's server or 3rd party service)
//                DemoHelper.getInstance().getUserProfileManager().asyncGetCurrentUserInfo();
//                DemoHelper.getInstance().asyncFetchContactsFromServer(null);
////                Intent intent = new Intent(LoginActivity.this,
////                        ConversationListActiviy.class);
////                startActivity(intent);
//
////                finish();
//            }
//
//            @Override
//            public void onProgress(int progress, String status) {
////                Log.d(TAG, "login: onProgress");
//            }
//
//            @Override
//            public void onError(final int code, final String message) {
////                Log.d(TAG, "login: onError: " + code);
////                if (!progressShow) {
////                    return;
////                }
////                mActivity.runOnUiThread(new Runnable() {
////                    public void run() {
//////                        pd.dismiss();
////                        Toast.makeText(getApplicationContext(), getString(com.chetuan.findcar.R.string.Login_failed) + message,
////                                Toast.LENGTH_SHORT).show();
////                    }
////                });
//            }
//        });
//    }
//
//    /**
//     * 判断sdk是否登录成功过，并没有退出和被踢
//     */
//    public static boolean isHuanXinLoggedInBefore(){
//        return EMClient.getInstance().isLoggedInBefore();
//    }
//
//
//}
